<template>
    <v-layout type="main">
        <el-form ref="form" :model="addForm" :rules="submitRules" label-width="120px" class="alick-add-form">
            <el-form-item label="版本" prop="version"  >
                <el-input type="text" v-model="addForm.version" readonly/>
            </el-form-item>
            <el-form-item label="提交信息" prop="commit_msg">
                <el-input type="textarea" :rows="6" v-model="addForm.commit_msg" />
            </el-form-item>
            <el-form-item label=" ">
                <el-button class="none-type" @click="submit" >确定</el-button>
            </el-form-item>

        </el-form>
    </v-layout>
</template>
  
<script>
import { getMarketModelVersionDetail, putMarketModelVersion, addMarketModelVersion } from '@/api/marketModelVersion'
export default {
    data() {
        return {
            active: 1,
            addForm:{ file_source: 1},
            model: {},
            submitRules: {
                commit: [
                    { required: true, message: "该项为必填项" },
                    { required: true, min: 1, max: 200, message: "长度在1到200个字符" },
                ],
            },
            model_id: this.$route.query.modelID,
            version: this.$route.query.version,
            model_version_id: this.$route.query.model_version_id,
            source: this.$route.query.source
        };
    },
    async created() {
        this.getDetail()
    },
    mounted() { },
    destroyed() { },
    methods: {
      
        /**
         * 提交
         */
        async submit() {
            this.$refs.form.validate(async (valid) => {
                if (valid) {
                    let data = { ...this.addForm }
                    if(data.id){
                        let ret = await putMarketModelVersion(data)
                        this.addForm = ret.data
                        this.toDetail()
                    }
                    else{
                        let ret = await addMarketModelVersion(data)
                        this.addForm = ret.data
                        this.toDetail()
                    }
                }
            })
        },
        toDetail() {
            let query = {
                id: this.addForm.model_id,
                active: 2
            }
            this.$router.push({
                path: '/market/code',
                query
            })
        },
        async getDetail() {
            if (this.$route.query.id) {
                let res = await getMarketModelVersionDetail(this.$route.query.id)
                this.model = res.data
                this.addForm = this.model
            }else{
                this.addForm.model_id = this.model_id
                this.addForm.version = 'v' + this.version
                this.addForm.source = this.source
            }
            console.log('addForm',this.addForm)
        },
        succeedOver(data) {
            console.log(data)
        },
    },
};
</script>
<style lang="less" scoped>
.el-form {
    margin-top: 20px;
}

.succeed-hit {
    text-align: center;
    line-height: 120px;
    font-size: 28px;
    font-weight: bold;
    padding-top: 80px;
}

.succeed-btn {
    width: 120px;
    margin: 40px auto 0;

    a {
        display: block;
        text-align: center;
        line-height: 40px;
        border-radius: 4px;
        background: #409EFF;
        color: #FFF;
    }
}
</style>